﻿/**
 *
 * Formulario filtro grid de movimientos
 *
 * @author Javier Caride Ulloa
 * @copyright (c) 2010, by Javier Caride Ulloa
 * @date April 26th, 2010
 * @version $Id:$
 *
 * @license FilterForm.ui.js is licensed under the terms of the Open Source GPL 3.0 license.
 *
 * License details: http://www.gnu.org/licenses/gpl.html
 */
FilterFormUi = Ext.extend(Ext.form.FormPanel, {
	frame : true,
	border : false,
	cleanButton : new Ext.Button({
		text: 'Limpiar'
	}),
	filterButton : new Ext.Button({
		text: 'Filtrar'
	}),
	initComponent : function() {
		if (this.initialConfig.filterTarget) {
			this.filterButton.on(
				'click', function() {
					var startDate = this.findById('startdt').getValue();
					var endDate = this.findById('enddt').getValue();
					if(startDate && endDate) {
						this.filterTarget.doFilterGrid(startDate.dateFormat('Y-m-d'),endDate.dateFormat('Y-m-d'));
					}
				}, this);
			
			this.cleanButton.on('click', function() {
					this.getForm().reset();
					this.filterTarget.doReloadGrid();
				}, this);
		}
		
		var config = {
			items : [
				{
					xtype: 'fieldset',
					title: 'Filtro movimientos',
					layout: 'form',
					items: [
						{
							xtype: 'container',
							autoEl: 'div',
							layout: 'hbox',
							items: [
								{
									xtype: 'container',
									autoEl: 'div',
									layout: 'form',
									items: [
										{
											xtype: 'datefield',
											width: 200,
											fieldLabel: 'Desde',
											name: 'startdt',
											id: 'startdt',
											vtype: 'daterange',
											endDateField: 'enddt' // id of the end date field
										}
									]
								},
								{
									xtype: 'container',
									autoEl: 'div',
									layout: 'form',
									items: [
										{
											xtype: 'datefield',
											width: 200,
											fieldLabel: 'Hasta',
											name: 'enddt',
											id: 'enddt',
											vtype: 'daterange',
											startDateField: 'startdt' // id of the start date field
										}
									]
								}
							]
						}				
					]
				}
			],
			buttons : [
				this.cleanButton,
				this.filterButton
			]
		}
		
		// Aplicamos la configuracion
		Ext.apply(this, Ext.apply(this.initialConfig, config));

		// Llamamos al constructor del padre
		FilterFormUi.superclass.initComponent.apply(this, arguments);

	}
});